C
C  PROGRAM READS FORMATTED MODEL INPUT OR output and unformatted
C  OUTPUT AND prints IT IN A FORMAT SUITABLE FOR LOADING
C  INTO AN INFO FILE THAT CAN TO BE RELATED OR JOINITEMED
C  TO POLYGON OR POINT COVERAGES.  The relate item is set up to be
c  seqnum, not rowcol.  
c
c  Current limits are 200 rows and 200 columns
C
c  modified by Lynette Brooks
c  September 12, 1991
c
      REAL ARRAY(200,200),dryvalue
      INTEGER COL,ROW,SEQNUM
      CHARACTER*80 INFILE,IFMT,OFILE,OFMT
      dimension text(4)    !text needed to read unformatted array
c  
C
C  TYPE IN INPUT AND OUTPUT FILE NAMES AND FORMATS.
C  NOTE THAT THE FORMAT FOR THE ARCFORM OUTPUT FILE CONTAINS
C  FORMATS FOR seqnum AND DATA ATTRIBUTES AND THAT THESE
C  ARE SEPERATED BY A COMMA IN THE OUTPUT FILE.
C
c  prompt for input and output filenames and formats
c  if formatted input, must also prompt for number of rows and columns
      write (6,*)'ours'
      WRITE (6,*) 'KEY IN INPUT FILE: '
      READ (5,'(a80)') INFILE
      WRITE (6,*) 'ENTER FORMAT OF INPUT FILE: Example (10f8.2)',
     1          'if unformatted enter UNF'
      READ (5,'(a80)') IFMT
      WRITE (6,*) 'ENTER NAME OF OUTPUT FILE: '
      READ (5,'(a80)') OFILE
      WRITE (6,*) 'ENTER FORMAT OF OUTPUT FILE,',
     1            'Example (I5,'','',F5.0):'
      READ (5,'(a80)') OFMT
      if (ifmt.eq.'unf'.or.ifmt.eq.'UNF') then
         open (unit=7,file=infile,status='old',form='unformatted')
      else
         OPEN (UNIT=7,FILE=INFILE,STATUS='OLD')
         write(6,*)' enter number of rows,columns'
         READ(5,*)ROW,col
      end if
      OPEN (UNIT=51,FILE=OFILE,STATUS='UNKNOWN')
      REWIND (UNIT=51)
c
c  read formatted or unformatted file
      if (ifmt.eq.'unf'.or.ifmt.eq.'UNF') then
         write(6,*)'enter value to use for dry nodes'
         read(5,*)dryvalue
         write(6,*)'enter time step, period, and layer wanted'
         read(5,*)istp,iper,ilay
 10      read (7) KSTP,KPER,PERTIM,TOTIM,TEXT,COL,ROW,KLAY
         read(7)((array(i,j),j=1,col),i=1,row)
         if ((kstp.ne.istp).or.(kper.ne.iper).or.(klay.ne.ilay)) then
            go to 10
         end if
      else
         do 12 i = 1,row
            READ(7,IFMT)(ARRAY(I,J),J=1,COL)
 12      continue
      end if
c
c  calculate seqnum so data can be related to model grid coverage
c
      DO 40 I=1,ROW
         DO 50 J=1,COL
         SEQNUM=((I-1)*COL)+J
         WRITE(51,OFMT)SEQNUM,ARRAY(I,J)
 50   CONTINUE
 40   CONTINUE
c
c  close files and end
c
      CLOSE (51)
      CLOSE (7)
      write(6,*)'ITS DONE'
      stop
      END
